package com.fss.model;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.fss.common.Constan;
import com.fss.utils.ExcelImportUtil;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;

public class TrainResourceModel extends Model<TrainResourceModel>{
	private static final long serialVersionUID = 1L;
	public static final TrainResourceModel DAO=new TrainResourceModel();
	public String getTime(){
		
		  SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMddhhmmssSSS");
		  Date date = new Date();
		  return(sdFormat.format(date));
	}
	//查询是否有该编号
	public Object getCurrent(String resourceId) {
		// TODO Auto-generated method stub
		return null;
	}
	public Page<Record> getSubjectList(int intValue, int i, String del_flag) {
		// TODO Auto-generated method stub
		 
		return null;
	} 
	//此上传是批量上传文件的写法
public Map uploadSubject(String subjectName,List<UploadFile> files ,String picturePath,String subjectDescribe,String path,String remark,String pathUrl){
	String sql = "insert into `px_subject` (subject_id,subject_name,subject_picture,subject_describe,create_date,remark,del_flag) values(?,?,?,?,?,?,?)";	
	 Map<String, Object> map = new LinkedHashMap();
	 String subjectId =getTime();//时间串化作为主键唯一识别
	 for(UploadFile file:files){
		 String fileName= file.getFileName();
		 Object[][] paras = new Object[1][7]; //此处若是插入多条数据，可以考虑循环()
	 if(!StrKit.isBlank(subjectName)){
		 paras[0][0]=subjectId;
		 paras[0][1]=subjectName;
		 paras[0][2]="http://"+Constan.WX_DOMAIN+ path+fileName;
		 paras[0][3]=subjectDescribe;
		 paras[0][4]=new Date();
		 paras[0][5]=remark;
		 paras[0][6] ="0";
		 }
		 else{
			 map.put("msg", "服务器异常！");
			 ExcelImportUtil.deleteDir(new File(pathUrl));
		 }
	 Db.batch(sql, paras, 100);
	 map.put("status","1");//代表上传成功
	 map.put("msg", "上传成功");
	 return map;
	 }
	 return map;
	
}
//默认获取全部科目
public List<Record> getList(String delFlag) {
	// TODO Auto-generated method stub
	String sql="select * from  px_subject where del_flag=?";
	List<Record> getListt=Db.find(sql,delFlag);
	return getListt;
}
	
}
